﻿namespace PillBox.Client.ViewModels
{
    using System;
    using System.Collections.Generic;
    using System.Windows.Input;
    using Microsoft.Practices.Composite.Presentation.Commands;
    using PillBox.Client.Framework;
    using PillBox.Client.Model;

    public class ScheduleDayItemViewModel : ViewModelBase
    {
        public ScheduleDayItemViewModel()
        {
            this.MedicationCommand = new DelegateCommand<object>(
                param =>
                {
                    ResultEnumerator.Begin(this.ViewMedication());
                });
        }

        private Person _person;
        public Person Person
        {
            get { return _person; }
            set
            {
                _person = value;
                RaisePropertyChanged(() => Person);
            }
        }

        private bool _isTaken;
        public bool IsTaken
        {
            get { return _isTaken; }
            set
            {
                _isTaken = value;
                RaisePropertyChanged(() => IsTaken);

                if (this.IsTaken)
                {
                    this.TakenTimestamp = DateTime.Now;
                }
                else
                {
                    this.TakenTimestamp = null;
                }
            }
        }

        private Medication _medication;
        public Medication Medication
        {
            get { return _medication; }
            set
            {
                _medication = value;
                RaisePropertyChanged(() => Medication);
            }
        }

        private DateTime _timeOfDay;
        public DateTime TimeOfDay
        {
            get { return _timeOfDay; }
            set
            {
                _timeOfDay = value;
                RaisePropertyChanged(() => TimeOfDay);
            }
        }

        private ICommand _medicationCommand;
        public ICommand MedicationCommand
        {
            get { return _medicationCommand; }
            set
            {
                _medicationCommand = value;
                RaisePropertyChanged(() => MedicationCommand);
            }
        }

        private DateTime? _takenTimestamp;
        public DateTime? TakenTimestamp
        {
            get { return _takenTimestamp; }
            set
            {
                _takenTimestamp = value;
                RaisePropertyChanged(() => TakenTimestamp);
            }
        }

        public IEnumerable<IResult> ViewMedication()
        {
            yield return Show.Screen<MedicationDetailsViewModel>().Configured(x => x.With(this.Medication));
        }
    }
}